<template>
  <div>
    <a-card>
      <p>
        <a-button @click='handleAdd' type='primary' icon='plus'>新增</a-button>
      </p>
      <!-- table区域-begin :scroll='{x:1280,y:innerHeight/2}'-->
      <a-table :scroll="{x: 1280}" bordered
               ref='table'
               size='middle'
               rowKey='id'
               :columns='columns'
               :dataSource='dataSource'
               :pagination='ipagination'
               :loading='loading'
               @change='handleTableChange'>
      <span slot='revision' slot-scope='text, record'>
        v.{{ text }}
      </span>
        <span slot='metaInfo' slot-scope='text, record'>
        <j-ellipsis :value='JSON.parse(text).description' :length='10' />
      </span>
        <!-- 字符串超长截取省略号显示-->
        <span slot='logContent' slot-scope='text, record'>
          <j-ellipsis :value='text' :length='10' />
        </span>
        <template slot='deploymentId' slot-scope='text,record'>
          <span v-if='record.deploymentId!=null' style='color: #7ac23c'>已部署</span>
          <span v-if='record.deploymentId==null' style='color: #ff0000'>未部署</span>
        </template>
        <span slot='action' slot-scope='text, record'>
        <a href='javascript:;' @click='openModeler(record.id)'>流程</a>
        <a-divider type='vertical' />
        <a-popconfirm title='确定部署吗?' @confirm='() => deployProcess(record.id)'>
          <a v-if='record.deploymentId!=null'>重新部署</a>
          <a v-else>部署</a>
        </a-popconfirm>
        <a-divider type='vertical' />
        <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
          <a>删除</a>
        </a-popconfirm>
      </span>
      </a-table>
    </a-card>
    <manage-edit-model ref='modalForm' v-on:reloadPage='loadData'></manage-edit-model>
  </div>
</template>

<script>
import { SearchListMixin } from '@/mixins/SearchListMixin'
import ManageEditModel from '@/views/activiti/model/ManageEditModel'
import { getAction } from '../../api/manage'
import { innerHeight } from '@/mixins/JeecgListMixin'

export default {
  name: 'Manage',
  mixins: [SearchListMixin],
  components: { ManageEditModel },
  data() {
    return {
      url: {
        page: '/act/model/page',
        delete: '/act/model/deleteModel',
        deploy: '/act/model/deployProcess'
      },
      /*columns: [
        {
          dataIndex: 'id',
          title: '编号',
          align: 'center'
        }, {
          dataIndex: 'name',
          title: '名称',
          align: 'center'
        }, {
          dataIndex: 'key',
          title: '模型标示',
          align: 'center'
        }, {
          dataIndex: 'category',
          title: '类别',
          align: 'center'
        }, {
          dataIndex: 'deploymentId',
          title: '状态',
          align: 'center',
          scopedSlots: { customRender: 'deploymentId' }
        }, {
          dataIndex: 'createTime',
          title: '创建时间',
          align: 'center'
        }, {
          title: '最后更新时间',
          dataIndex: 'lastUpdateTime',
          align: 'center'
        }, {
          title: '操作',
          dataIndex: 'action',
          width: '150px',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ]*/
      columns: [
        {
          title: '#',
          width: 50,
          dataIndex: '',
          key: 'rowIndex',
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '模型id',
          align: 'center',
          dataIndex: 'id'
        },
        {
          title: '模型名称',
          align: 'center',
          dataIndex: 'name',
          scopedSlots: { customRender: 'logContent' }
        },
        {
          title: '模型key',
          dataIndex: 'key',
          align: 'center'
        },
        {
          dataIndex: 'deploymentId',
          title: '状态',
          align: 'center',
          scopedSlots: { customRender: 'deploymentId' }
        },
        {
          title: '版本',
          dataIndex: 'revision',
          align: 'center',
          scopedSlots: { customRender: 'revision' }
        },
        {
          title: '备注描述',
          dataIndex: 'metaInfo',
          align: 'center',
          scopedSlots: { customRender: 'metaInfo' }
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          align: 'center'
          // sorter:true
        },
        {
          title: '最后更新时间',
          dataIndex: 'lastUpdateTime',
          align: 'center'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ]
    }
  },
  created() {
  },
  methods: {
    openModeler(id) {
      this.$router.push({ path: '/activiti/modelerEdit', query: { modelId: id } })
    },
    deployProcess(id) {
      getAction(this.url.deploy, { modelId: id }).then(res => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.error(res.message)
        }
      })
    }
  }
}
</script>

<style lang='less' scoped>

</style>